package com.prize.dtos;

import com.prize.enums.CodeEnum;

import java.io.Serializable;

/**
 * @descriptions: 通用的结果返回类
 * @author: yunqiang
 * @date: 2022/5/28 11:06
 */
public class ResponseResult<T> implements Serializable {

    /**
     * 返回状态码
     */
    private int code;

    /**
     * 提示信息
     */
    private String msg;

    /**
     * 数据类型
     */
    private T data;

    /**
     * 总页数
     */
    private long total;


    public static <T> ResponseResult<T> success( String msg) {
        ResponseResult result = new ResponseResult();
        result.setCode(CodeEnum.SUCCESS.getCode());
        result.setMsg(msg);
        return result;
    }



    public static <T> ResponseResult<T> success(long total, Object obj) {
        ResponseResult result = new ResponseResult();
        result.setCode(CodeEnum.SUCCESS.getCode());
        result.setTotal(total);
        result.setMsg(CodeEnum.SUCCESS.getErrorMessage());
        result.setData(obj);
        return result;
    }
    public static ResponseResult success() {
        ResponseResult result = new ResponseResult();
        result.setCode(CodeEnum.SUCCESS.getCode());
        result.setMsg(CodeEnum.SUCCESS.getErrorMessage());
        return result;
    }

    public static <T> ResponseResult<T> successResult(Object obj) {
        ResponseResult result = new ResponseResult();
        result.setCode(CodeEnum.SUCCESS.getCode());
        result.setMsg(CodeEnum.SUCCESS.getErrorMessage());
        result.setData(obj);
        return result;
    }

    public static ResponseResult errorResult() {
        ResponseResult result = new ResponseResult();
        result.setCode(CodeEnum.ERROE.getCode());
        result.setMsg(CodeEnum.ERROE.getErrorMessage());
        return result;
    }


    public static ResponseResult<Object> noResult() {
        ResponseResult result = new ResponseResult();
        result.setCode(CodeEnum.NO_RESULT.getCode());
        result.setMsg(CodeEnum.NO_RESULT.getErrorMessage());
        return result;
    }

    public static ResponseResult errorParameter() {
        ResponseResult result = new ResponseResult();
        result.setCode(CodeEnum.ERROR_PARAMETER.getCode());
        result.setMsg(CodeEnum.ERROR_PARAMETE.getErrorMessage());
        return result;
    }

    public static ResponseResult error(int code, String msg) {
        ResponseResult result = new ResponseResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static ResponseResult success(int code, String msg) {
        ResponseResult result = new ResponseResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


    public void setCode(int code) {
        this.code = code;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public long getTotal() {
        return total;
    }

    public int getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
